<template>
  <a-modal
    width="500px"
    v-bind="modalOption"
    :okText="false"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model layout="horizontal" labelAlign="right" ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :model="form" :rules="validatorRules">
        <a-form-model-item label="原业务员" prop="fromBizMan">
          <z-select-multi-user :multiple="false" v-model="form.fromBizMan" />
        </a-form-model-item>
        <a-form-model-item label="新业务员" prop="toBizMan">
          <z-select-multi-user :multiple="false" v-model="form.toBizMan" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import ModalFormMixin from '@/mixins/ModalFormMixin'
import ZSelectMultiUser from '@/components/zzbiz/ZSelectMultiUser'
import { putAction } from '@/services/manage'
export default {
  nam: 'TransferManModal',
  components: {
    ZSelectMultiUser
  },
  mixins: [ModalFormMixin],
  data() {
    return {
      validatorRules: {
        fromBizMan: [{ required: true, message: '请选择原业务员!' }],
        toBizMan: [{ required: true, message: '请选择新业务员!' }]
      },
      url: {
        save: '/erp/sales/cst/transfer/'
      },
      pnCodes: '',
      title: '客户转移'
    }
  },
  methods: {
    show(data) {
      this.visible = true
      this.pnCodes = data
    },
    handleOk() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.request(this.form)
        }
      })
    },
    request(formData) {
      this.confirmLoading = true
      putAction(this.url.save + formData.fromBizMan + '/' + formData.toBizMan).then(res => {
        if (res.success) {
          this.$message.success('操作成功')
          this.close()
          this.$emit('ok')
        }
        this.confirmLoading = false
      })
    }
  }
}
</script>
